<script setup lang="ts">
import { onMounted } from 'vue';
import { useAuthStore } from './store/auth';

const authStore = useAuthStore();

onMounted(() => {
  // 检查localStorage中的token是否存在
  const token = localStorage.getItem('access_token');
  const expiresAt = localStorage.getItem('token_expires_at');

  if (token && expiresAt) {
    // 检查token是否过期
    const expiresAtTimestamp = parseInt(expiresAt);
    const now = Date.now();

    if (expiresAtTimestamp > now) {
      // token未过期，恢复登录状态
      authStore.setToken(token, expiresAtTimestamp);
    } else {
      // token已过期，清除登录状态
      authStore.clearToken();
    }
  }
});
</script>

<template>
  <router-view />
</template>

<style>
#app {
  width: 100%;
  height: 100%;
}
</style>
